<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的收藏</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            color: #333;
            margin: 0;
            padding: 20px;
            transition: background-color 0.5s, color 0.5s;
        }
        .container {
            max-width: 800px;
            margin: auto;
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            transition: background-color 0.5s;
        }
        h1 {
            text-align: center;
            color: #007bff;
        }
        .favorite-list {
            margin-top: 20px;
        }
        .favorite-list h2 {
            color: #007bff;
        }
        .favorite-list ul {
            list-style: none;
            padding: 0;
        }
        .favorite-list li {
            padding: 10px;
            border-bottom: 1px solid #eee;
            display: flex;
            justify-content: space-between;
            align-items: center;
            transition: background-color 0.5s, color 0.5s;
        }
        .favorite-list li:last-child {
            border-bottom: none;
        }
        .favorite-list a {
            color: #007bff;
            text-decoration: none;
            transition: color 0.5s;
        }
        .favorite-list a:hover {
            text-decoration: underline;
        }
        .favorite-list .remove-button {
            font-size: 1em;
            cursor: pointer;
            color: #ff0000;
            transition: color 0.5s;
        }
        .favorite-list .remove-button:hover {
            color: #cc0000;
        }
        .mode-toggle {
            position: fixed;
            top: 20px;
            right: 20px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            cursor: pointer;
            font-size: 1.2em;
            transition: background-color 0.5s, transform 0.5s;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .mode-toggle:hover {
            background-color: #0056b3;
            transform: scale(1.1);
        }
    </style>
</head>
<body>
    <button class="mode-toggle" onclick="toggleMode()">🌙</button>
    <div class="container">
        <h1>我的收藏</h1>
        <div class="favorite-list">
            <h2>收藏夹</h2>
            <ul id="favoriteList">

            </ul>
        </div>
    </div>

    <script>
        var favorites = [];
        if (localStorage.getItem("favorites")) {
            favorites = JSON.parse(localStorage.getItem("favorites"));
        }

        // 更新收藏夹列表
        function updateFavoritesList() {
            var favoriteList = document.getElementById("favoriteList");
            favoriteList.innerHTML = "";

            if (favorites.length === 0) {
                favoriteList.innerHTML = "<p>您的收藏夹为空。</p>";
            } else {
                favorites.forEach(function(item) {
                    var listItem = document.createElement("li");
                    listItem.innerHTML = '<a href="' + item.url + '">' + item.name + '</a> <span class="remove-button" onclick="removeFavorite(\'' + item.name + '\', \'' + item.url + '\')">移除</span>';
                    favoriteList.appendChild(listItem);
                });
            }
        }

        function removeFavorite(name, url) {
            favorites = favorites.filter(function(item) {
                return !(item.name === name && item.url === url);
            });
            localStorage.setItem("favorites", JSON.stringify(favorites));
            updateFavoritesList();
            alert("已取消收藏！");
        }

        function toggleMode() {
            var body = document.body;
            var container = document.querySelector('.container');
            var button = document.querySelector('.mode-toggle');
            var links = document.querySelectorAll('.favorite-list a');
            var removeButtons = document.querySelectorAll('.favorite-list .remove-button');
            if (body.style.backgroundColor === 'rgb(16, 16, 16)') {
                body.style.backgroundColor = '#f0f0f0';
                body.style.color = '#333';
                container.style.backgroundColor = '#fff';
                button.textContent = '🌙';
                links.forEach(link => link.style.color = '#007bff');
                removeButtons.forEach(button => button.style.color = '#ff0000');
            } else {
                body.style.backgroundColor = '#101010';
                body.style.color = '#fff';
                container.style.backgroundColor = '#333';
                button.textContent = '☀️';
                links.forEach(link => link.style.color = '#80d0ff');
                removeButtons.forEach(button => button.style.color = '#ff6666');
            }
        }

        updateFavoritesList();
    </script>
</body>
</html>

